import * as Sentry from '@sentry/vue';
import { Integrations } from '@sentry/tracing';

// const sentryDsn = 'https://57370d6a34814bda98ebc62551b92e91@sentry.heals.net.cn/3';
const sentryDsn = 'https://72fd5c6598f247ea88a77f645be71a36@sentry.heals.net.cn/4';

export function createSentry(app, router) {
  Sentry.init({
    app,
    dsn: sentryDsn,
    integrations: [new Integrations.BrowserTracing()],
    routingInstrumentation: Sentry.vueRouterInstrumentation(router),
    tracingOrigins: ['mp.heals.net.cn', '127.0.0.1', 'localhost'],
    tracesSampleRate: 0.8
  });
}

export function uploadNetErrorEvent(error) {
  Sentry &&
    Sentry.withScope(function (scope) {
      // 设置请求信息
      scope.setExtra('request headers', error.config.headers);
      scope.setExtra('request params', error.config.params);
      scope.setExtra('request data', error.config.data);

      // 设置响应信息
      if (error.response) {
        scope.setExtra('response status', error.response.status);
        scope.setExtra('response headers', error.response.headers);
        scope.setExtra('response data', error.response.data);
      }
      // 创建异常描述
      let err = new Error('接口地址：' + error.config.url);
      err.name = '接口请求错误';
      // 手动捕获异常
      Sentry.captureException(err);
    });
}
